//-----------------------------------------------------------------------
// <copyright file="TestAllFiles.cs" company="Anthony Steele">
// This source forms part of the DuplicateFinder utility
// Hosted at http://www.codeplex.com/DuplicateFinder
//
// This source is available under the terms of the Microsoft Public License (Ms-PL)
// See http://duplicatefinder.codeplex.com/license
// All other rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace DuplicateFinder.TestLibrary
{
    using DuplicateFinderLib;
    
    using NUnit.Framework;
    
    /// <summary>
    /// Test running the duplicatefinder against all test files
    /// </summary>
    [TestFixture]
    public class TestAllFiles 
    {
        /// <summary>
        /// Excpected count of files
        /// </summary>
        private const int TestFileCount = 9;

        /// <summary>
        /// Test all files with .txt extension
        /// </summary>
        [Test]
        public void TestAllTextFiles()
        {
            FileDuplicateFinderTester tester = new FileDuplicateFinderTester();
            FileDuplicateFinder process = tester.Process;
            Assert.IsNotNull(process);

            process.ReadFile(TestUtils.FullTestFilePath(), "*.txt", false);
            process.FindDuplicates();

            Assert.AreEqual(TestFileCount, process.ReadCount);
            Assert.AreEqual(7, tester.DuplicateCount);
        }

        /// <summary>
        /// Test with an excluded file
        /// </summary>
        [Test]
        public void TestExcludeFile()
        {
            FileDuplicateFinderTester tester = new FileDuplicateFinderTester();
            FileDuplicateFinder process = tester.Process;
            Assert.IsNotNull(process);

            process.AddExcludedFileName("Text1.txt");
            process.ReadFile(TestUtils.FullTestFilePath(), "*.txt", false);
            process.FindDuplicates();

            Assert.AreEqual(TestFileCount - 1, process.ReadCount);
        }

        /// <summary>
        /// Test with a focus file set to an invalid value
        /// </summary>
        [Test]
        public void TestAllFilesFocusWrong()
        {
            FileDuplicateFinderTester tester = new FileDuplicateFinderTester();
            FileDuplicateFinder process = tester.Process;
            Assert.IsNotNull(process);
            
            process.ReadFile(TestUtils.FullTestFilePath(), "*.txt", false);
            int processedCount = process.FindDuplicates("nosuchfile.txt");

            Assert.AreEqual(0, processedCount);
            Assert.AreEqual(TestFileCount, process.ReadCount);
            Assert.AreEqual(0, tester.DuplicateCount);
        }

        /// <summary>
        /// Test with a valid focus file
        /// </summary>
        [Test]
        public void TestAllFilesFocusOne()
        {
            FileDuplicateFinderTester tester = new FileDuplicateFinderTester();
            FileDuplicateFinder process = tester.Process;
            Assert.IsNotNull(process);

            process.ReadFile(TestUtils.FullTestFilePath(), "*.txt", false);
            int processedCount = process.FindDuplicates("TestProgram.txt");

            Assert.AreEqual(1, processedCount);
            Assert.AreEqual(TestFileCount, process.ReadCount);
            Assert.AreEqual(0, tester.DuplicateCount);
        }
    }
}
